@extends('Layouts.iframe')
<style>
    .select{
        width: 70%;
    }
    #myform{
        line-height: 3;
    }
    #myform div{
            line-height: 3;
    }
    #myform input{
        width: 70%;
    }
    #myform label{
        display: inline-block;
        width: 75px;
    }
    .select-box{
        width: 70%;
    }
    .w70{
        width: 70% !important;
    }
    .w34{
        width: 34% !important;
    }
</style>
@section('content')

    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 签单管理 <span class="c-gray en">&gt;</span> 签单管理列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>

    <div class="page-container">
        @if(auth()->user()->can('order.search') or auth()->user()->can('order.export'))
        <div class="text-l">
            <form action="{{route('order.index')}}" method="get" id="myform">
                <div class="text-l">
                    <div class="col-sm-6 col-md-4">
                        <label for="">借款人 ： </label>
                        <input type="text" name="customer" value="{{$orders->customer}}" placeholder=" 借款人"  class="input-text">
                    </div>
                    <div class="col-sm-6 col-md-4">
                        <label for="">联系电话 ： </label>
                        <input type="text" name="phone" value="{{$orders->phone}}" placeholder=" 联系电话"  class="input-text">
                    </div>
                    <div class="col-sm-6 col-md-4">
                        <label for="">签单渠道 ：</label>
                        <input type="text" name="my_company" value="{{$orders->my_company}}" id="" placeholder=" 签单渠道"  class="input-text">
                    </div>
                    <div class="col-sm-6 col-md-4">
                        <label for="">签单人 ：</label>
                        <input type="text" name="manager" value="{{$orders->manager}}" id="" placeholder=" 签单人"  class="input-text">
                    </div>
                    <div class="col-sm-6 col-md-4">
                        <label for="">申请时间 ：</label>
                        <input type="text" style="width: 30%;" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'logmax\')||\'%y-%M-%d\'}' })" id="logmin" class="input-text Wdate" name="create_time_start"  value="{{$orders->create_time_start}}">
                        -
                        <input type="text" style="width: 30%;" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'logmin\')}',maxDate:'%y-%M-%d' })" id="logmax" class="input-text Wdate" name="create_time_end"  value="{{$orders->create_time_end}}">
                    </div>
                    <div class="col-sm-6 col-md-4">
                        <label for="">分销渠道 ：</label>
                        <input type="text" name="parent_company" value="{{$orders->parent_company}}" id="" placeholder=" 分销渠道"  class="input-text">
                    </div>
                    <div class="col-sm-6 col-md-4">
                        <label for="">分销人 ：</label>
                        <input type="text" name="parent_manager" value="{{$orders->parent_manager}}" id="" placeholder=" 分销人"  class="input-text">
                    </div>
                    <div class="col-sm-6 col-md-4">
                        <label for="">产品分类：</label>
                        <span class="select-box inline w34">
                    <select name="category_id_first" class="select" >

                            <option value="">全部类型</option>
                            @if($categories->count())
                                @foreach($categories as $category)
                                    <option value="{{$category->id}}" {{$category->id==$orders->category_id_first?'selected':''}}>{{$category->name}}</option>
                                @endforeach
                            @endif
                    </select>
                    </span>
                    <span class="select-box inline w34">
                    <select name="category_id_second" class="select" >
                            <option value="">全部类型</option>
                            @if($orders->category_id_first)
                                @if($second_categories!=null)
                                    @foreach($second_categories as $second_category)
                                        <option value="{{$second_category->id}}" {{$second_category->id==$orders->category_id_second?'selected':''}}>{{$second_category->name}}</option>
                                    @endforeach
                                @endif
                            @endif
                    </select>
                    </span>
                    </div>
                    <div class="col-sm-6 col-md-4">
                        <label for="">所属机构 ：</label>
                        <span class="select-box inline w70">
                    <select name="agent_id" class="select" >

                            <option value="">全部机构</option>
                        @if($agents->count())
                            @foreach($agents as $agent)
                                <option value="{{$agent->id}}" {{$agent->id==$orders->agent_id?'selected':''}}>{{$agent->name}}</option>
                            @endforeach
                        @endif

                    </select>
                    </span>
                    </div>
                    <div class="col-sm-6 col-md-4">
                        <label for="">产品名称 ：</label>
                        <input type="text" name="product_name" value="{{$orders->product_name}}" id="" placeholder="产品名称"  class="input-text">
                    </div>
                    <div class="col-sm-6 col-md-4">
                        <label for="">订单状态 : </label><span class="select-box inline w70">
                    <select name="status" class="select" >
                        <option value=""  @if($orders->status == '') selected  @endif>不限</option>
                        <option value="0" @if($orders->status == '0') selected @endif>申请中</option>
                        <option value="1"  @if($orders->status == '1') selected @endif>放款</option>
                        <option value="-1"  @if($orders->status == '-1') selected  @endif>退单</option>
                    </select>
                    </span>
                    </div>
                    @can('order.search')
                        <button  id="submit" class="btn btn-success" type="submit"><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
                    @endcan
                    @can('order.export')
                        <span   class="btn btn-success" onclick="exportExcel()"> 导出Excel </span>
                    @endcan
                </div>
            </form>
        </div>
        @endif
        <div class="cl pd-5 bg-1 bk-gray mt-20">
            {{--<span class="r">
                <a class="btn btn-primary radius" onclick="" href="javascript:;">
                    <i class="Hui-iconfont">&#xe600;</i>新增机构
                </a>
            </span>--}}
        </div>
        <div class="mt-20">
            <table class="table table-border table-bordered table-bg table-hover table-sort table-responsive">
                <thead>
                <tr class="text-c">
                    <th width="25"><input type="checkbox" name="" value=""></th>
                    <th width="80">ID</th>
                    <th width="200">借款人</th>
                    <th width="200">联系电话</th>
                    <th width="320">身份证号码</th>
                    <th width="100">产品分类</th>
                    <th width="100">所属机构</th>
                    <th width="100">产品名称</th>
                    <th width="100">放款金额</th>
                    <th width="100">签单渠道</th>
                    <th width="200">签单人</th>
                    <th width="155">申请时间</th>
                    <th width="100">分销渠道</th>
                    <th width="80">分销人</th>
                    <th width="30">状态</th>
                    {{--@if(auth()->user()->can('order.show') or auth()->user()->can('order.edit') or auth()->user()->can('order.logs'))--}}
                    <th width="300">操作</th>
                    {{--@endif--}}
                </tr>
                </thead>
                <tbody>
                @if($orders->count())
                    @foreach($orders as $order)
                <tr class="text-c">
                    <td><input type="checkbox" value="{{$order->id}}" name=""></td>
                    <td>{{$order->id}}</td>
                    <td>{{$order->userinfo['customer']}}</td>
                    <td>{{$order->userinfo['phone']}}</td>
                    <td>{{$order->userinfo['idcard']}}</td>
                    <td> @if(array_key_exists('category_name_first',$order->confirm_loan)) {{$order->confirm_loan['category_name_first']}}-{{$order->confirm_loan['category_name_second']}}@else -- @endif</td>
                    <td>@if(array_key_exists('agent_name',$order->confirm_loan)) {{$order->confirm_loan['agent_name']}}@else -- @endif</td>
                    <td>@if(array_key_exists('product_name',$order->confirm_loan)) {{$order->confirm_loan['product_name']}}@else -- @endif</td>
                    <td>@if(array_key_exists('loan_amount',$order->confirm_loan)) {{$order->confirm_loan['loan_amount']}}（万）@else -- @endif </td>
                    <td>{{$order->channel_info['my_company']}}</td>
                    <td>{{$order->channel_info['manager']}}</td>
                    <td>{{$order->created_at}}</td>
                    <td>@if(array_key_exists('parent_company',$order->channel_info)){{$order->channel_info['parent_company']}}@endif</td>
                    <td>@if(array_key_exists('parent_manager',$order->channel_info)){{$order->channel_info['parent_manager']}}@endif</td>

                    @if($order->status==0)
                        <td class="td-status"><span class="label label-primary radius">申请中</span></td>
                        @elseif($order->status=='-1')
                        <td class="td-status"><span class="label label-defaunt radius">退单</span></td>
                        @elseif($order->status=='1')
                        <td class="td-status"><span class="label label-success radius">放款</span></td>
                        @endif


                    <td class="f-14 td-manage">
                        @can('order.show')
                        <a style="text-decoration:none"  href="{{route('order.show',['id'=>$order->id])}}" title="查看" class="label label-secondary radius">查看</a>
                        @endcan
                        @can('order.edit')
                        <a style="text-decoration:none" class="ml-5 label label-primary  radius"  href="{{route('order.edit',['id'=>$order->id])}}" title="处理">处理</a>
                        @endcan
                        @can('order.logs')
                        <a style="text-decoration:none" class="ml-5 label label-secondary radius" onClick="order_log('操作日志','{{url('admin/order/orderLogs',['id'=>$order->id])}}','','510')" href="javascript:;" title="操作日志">操作日志</a>
                        @endcan
                    </td>
                </tr>
                    @endforeach
                @endif
                </tbody>

            </table>
            <div id="pull_right">
                <div class="pull-right">
                    {!! $orders->render() !!}
                </div>
            </div>
        </div>
    </div>

@endsection
@section('js')
    <script type="text/javascript" src="/js/lib/WdatePicker.js"></script>
    <script type="text/javascript" src="/js/lib/jquery.dataTables.min.js"></script>
    <script type="text/javascript" src="/js/lib/laypage.js"></script>
    <script>
        var _token="{{csrf_token()}}";
        //操作日志
        function order_log(title,url,w,h){
            layer_show(title,url,w,h);
        }

        /*一级分类联动二级分类*/
        $('select[name="category_id_first"]').on('change',function () {
            var html="<option value=''>全部类型</option>";
            var id=$(this).val();
            if(!id){
                $('select[name="category_id_second"]').html(html);
                return false;
            }

            $.post("{{url('admin/getSecondCategory')}}",{'_token':_token,'id':id},function (data) {
                if(data.length>0){
                    $.each(data,function (key,value) {
                        html += "<option value='"+value.id+"'>"+value.name+"</option>";
                    });
                }
                $('select[name="category_id_second"]').html(html);
            });
        });

        function exportExcel(){
            layer.msg('默认导出全部数据，需要指定行请勾选',{icon:1,time:3000});
            var groupCheckbox=$("input[type='checkbox']");
            var val = '';
            for(i=0;i<groupCheckbox.length;i++){
                if(groupCheckbox[i].checked){
                    if(groupCheckbox[i].value) {
                        val += ',' + groupCheckbox[i].value;
                    }
                }
            }
            if (val.substr(0,1)==',') val=val.substr(1);
            if(val.length > 0) {
                window.location.href = '/admin/order/export/'+val;
            }else{
//                layer.msg('请先选中要导出的数据',{icon:2,time:1000});
                window.location.href = '/admin/order/export/all';
            }
        }

    </script>
@endsection